<template>
  <van-popup round v-model="show_sub_add" @close="close_pop">
    <div class="form">
      <div class="title">
        <div class="c_flex" style="padding:10px">添加任务</div>
      </div>
      <van-form validate-trigger="onSubmit" validate-first @submit="onSubmit">


        <time_picker icons="start" v-model="user_data.start_time" txt_tip="开始时间" />
        <time_picker icons="end" v-model="user_data.end_time" txt_tip="结束时间" />



        <van-field autocomplete="off" v-model="user_data.task_amount" name="car_raw" placeholder="填写任务数"
          :rules="[{required: true,message: '请填写任务数'}]">
          <template #left-icon>
            <svg-icon class-name="icon_size" icon-class="car" />
          </template>

        </van-field>

        <div class="submit_out c_flex">
          <van-button native-type="submit" class="submit">确定</van-button>
        </div>
      </van-form>
    </div>
  </van-popup>
</template>

<script>
  import {
    ShoperService
  } from '@/api';
  import time_picker from '@/components/TimePicker/index.vue';
  export default {
    name: 'add_task',
    props: {
      show_add: Boolean,
      shoper_id: String,

    },
    components: {
      time_picker,
    },
    computed: {
      now_date() {
        return new Date();
      },
      show_sub_add: {
        get() {
          return this.show_add
        },
        set(value) {
          console.log(value);
          if (!value) {
            this.close_pop();
          }
        }
      }
    },
    
    data() {
      return {
        user_data: {
          start_time: new Date().toISOString().split('T')[0],
          end_time: new Date().toISOString().split('T')[0],
          task_amount: '',
        },
        show_start: false,
        show_end: false,
      }
    },
    watch: {

    },
    methods: {
     
      changeCalendar(val) {

        this.user_data.start_time = val.format('YYYY-MM-DD');
      },
      onSubmit() {
        if(this.user_data.start_time > this.user_data.end_time){
          this.$toast("结束时间不能小于开始时间！")
          return ;
        }
        ShoperService.addSale(this.user_data, this.shoper_id).then(res => {
          console.log(res)
          this.close_pop();
        });
      },
      close_pop() {
        this.empty();
        this.$emit('update:show_add', false);
      },
      empty() {
        this.user_data = {
          start_time: '',
          end_time: '',
          task_amount: '',
        }
      }
    },
  }
</script>

<style lang="less" scoped>
  .icon_size {
    width: 30px;
    height: 30px;
    margin-right: 15px;
  }

  .form {
    .title {
      width: 50%;
      border-bottom: 1px solid rgba(153, 153, 153, 1);
      margin: 0 auto 15px;
    }

    width:450px;


    .submit_out {
      margin-top: 40px;
      margin-bottom: 30px;
    }

    .submit {

      width: 360px;
      height: 70px;
      border-radius: 37.84px;
      background-color: rgba(235, 95, 17, 1);
      letter-spacing: 1.8px;
      font-size: 28px;
      color: rgba(255, 255, 255, 1);
    }
  }
</style>